#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<string.h>
#include<stdlib.h>

int main()
{
    pid_t child_pid;
    char str[100]={0};
    child_pid=fork();
    if(child_pid<0)
    {
        printf("fork create failed!\n");
        exit(-1);
    }
    else if(child_pid==0)
    {
        while(1)   //xie  scanf
        {
            memset(str,0,100);
            printf("this is a child process!\n");
            FILE *file=fopen("test.txt","w");
            fread(str,100,1,file);
            fwrite(str,sizeof(str),1,file);
            // fclose(file);
        }
    }
    else
    {
        while(1)
        {
            memset(str,0,sizeof(str));
            printf("this is a parent process!\n");
            FILE *file=fopen("test.txt","r");
            fread(str,100,1,file);
            printf("str:%s\n",str);
            sleep(2);
        }
    }
}
